package com.bieyang.anjia.ui.activity;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bieyang.anjia.R;
import com.bieyang.anjia.module.NewsInfo;
import com.bieyang.anjia.sqlitedatabase.AnjiaSQLiteOpenHelper;
import com.bieyang.anjia.sqlitedatabase.SqliteOperation;
import com.bieyang.anjia.utils.Constants;
import com.bieyang.anjia.utils.Show;

/**
 * 查看详细资讯
 * */
public class AcAnjiaXieyi extends BaseFlingActivity {
	Button btnBack;
	RelativeLayout rlYuShe, newsDetail;
	Context con;
	List<NewsInfo> newsList;
	WebView webNews;
	String webUrl, fromAcMain;

	@SuppressLint("HandlerLeak")
	private Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {

			switch (msg.what) {
			case Constants.GET_NEWS_SUCESS:
				SqliteOperation sqlOperation = new SqliteOperation(con,
						AnjiaSQLiteOpenHelper.dbName,
						AnjiaSQLiteOpenHelper.version);
				newsList = sqlOperation.queryNews("isdelete=?",
						new String[] { "F" }, null);
				// newsList=msg.getData().getParcelable("newsInfo");
				// Log.d("newsList", newsList.toString());
				Show.toast(AcAnjiaXieyi.this, R.string.tip_get_news_ok);
				break;
			case Constants.GET_NEWS_FAIL:
				Show.toast(AcAnjiaXieyi.this, R.string.tip_get_news_fail);
				break;
			default:
				break;
			}
		};
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ac_help_detail);
		con = AcAnjiaXieyi.this;
		TextView tvTitle = (TextView) findViewById(R.id.tvTitle);
		tvTitle.setText("安加注册协议");
		webUrl = getIntent().getStringExtra("webUrl");
		initView();
	}

	@SuppressLint("SetJavaScriptEnabled")
	private void initView() {
		OnClick onClick = new OnClick();
		btnBack = (Button) findViewById(R.id.btnBack);
		btnBack.setOnClickListener(onClick);
		// String url="http://www.baidu.com";
		webNews = (WebView) findViewById(R.id.webNews);
		webNews.getSettings().setJavaScriptEnabled(true);
		// if("fromAcMain".equals(fromAcMain)){
		webUrl = "http://service.anjia360.cn:81/registrationAgreement.html";
		webNews.loadUrl(webUrl);
		webNews.setWebViewClient(new MyWebViewClient());
		return;
		// }
		// if ("".equals(webUrl)) {
		// Show.toast(con, "当前无数据");
		// }else{
		// webNews.loadUrl(webUrl);
		// webNews.setWebViewClient(new MyWebViewClient());
		// }
	}

	/**
	 * 页面内跳转
	 * */
	public boolean shouldOverrideUrlLoading(WebView view, String url) {
		if (url.indexOf("tel:") < 0) {// 页面上有数字会导致连接电话
			view.loadUrl(url);
		}
		return true;
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	class OnClick implements android.view.View.OnClickListener {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.btnBack:
				finish();
				break;
			// case R.id.rlYuShe:
			// startActivity(new Intent(AcFindNews.this,AcMobanYushe.class));
			// break;
			default:
				break;
			}
		}
	}

	// Web视图
	private class MyWebViewClient extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			return true;
		}
	}

}